package top.dprkshow.practice.graph;

import edu.princeton.cs.algs4.Bag;

/**
 * @author Kent HAN
 * @date 2021/9/17
 */
public class WeightedDigraph {
    int v;
    Bag<WeightedDirectedEdge>[] adjBagList;

    public WeightedDigraph(int v) {
        this.v = v;
        adjBagList= (Bag<WeightedDirectedEdge>[]) new Bag[v];
        for (int i = 0; i < v; i++) {
            adjBagList[i] = new Bag<>();
        }
    }

    public void addEdge(WeightedDirectedEdge e) {
        int v = e.from();
        adjBagList[v].add(e);
    }

    public Iterable<WeightedDirectedEdge> adj(int v) {
        return adjBagList[v];
    }
}
